from flask_wtf import FlaskForm
from wtforms import StringField, FloatField, SubmitField, SelectField, PasswordField
from wtforms.validators import DataRequired, Length, NumberRange

class StudentForm(FlaskForm):
    student_id = StringField('学号', validators=[DataRequired(), Length(max=64)])
    name = StringField('姓名', validators=[DataRequired(), Length(max=128)])
    class_name = StringField('班级', validators=[Length(max=64)])
    submit = SubmitField('提交')

class CourseForm(FlaskForm):
    course_code = StringField('课程编号', validators=[DataRequired(), Length(max=64)])
    name = StringField('课程名称', validators=[DataRequired(), Length(max=128)])
    credit = FloatField('学分', validators=[DataRequired(), NumberRange(min=0)])
    submit = SubmitField('提交')

class GradeForm(FlaskForm):
    student = SelectField('学生', coerce=int, validators=[DataRequired()])
    course = SelectField('课程', coerce=int, validators=[DataRequired()])
    score = FloatField('分数', validators=[DataRequired(), NumberRange(min=0, max=100)])
    grade_status = StringField('成绩状态', validators=[Length(max=32)])
    submit = SubmitField('提交')

class LoginForm(FlaskForm):
    username = StringField('用户名', validators=[DataRequired(), Length(max=64)])
    password = PasswordField('密码', validators=[DataRequired()])
    submit = SubmitField('登录')
